////////////////////////////////////////////////////////////////////////////////
//
//	Original file Name: InputButton.java
//	Originating Author: JWhitefield
//	
//	Description: Represents the implementation of a single button in a certain state 
//
////////////////////////////////////////////////////////////////////////////////

package com.jjw.game.input;

import com.jjw.game.ITickable;

/**
 * Represents the implementation of a single button in a certain state 
 * 
 * @author JWhitefield
 *
 */
public class InputButton implements ITickable {
	
	//--------------------------------------------------------------------------
	//
	//Properties
	//
	//--------------------------------------------------------------------------
	
	//----------------------------------
	// Public
	//----------------------------------
		
	//----------------------------------
	//  Getters / Setters
	//----------------------------------
	
	/**
	 * Is the input button current down 
	 * 
	 * @return boolean to that effect
	 */
	public boolean isDown() {
		return this.down;
	}
	
	/**
	 * Is the input button clicked
	 * @return
	 */
	public boolean isClicked() {
		return clicked;
	}

	private void setClicked(boolean clicked) {
		this.clicked = clicked;
	}
	
	//----------------------------------
	// Private
	//----------------------------------
	
	/**
	 * Count on the presses of the key
	 */
	private int presses;
	
	/**
	 * Absorbs gives time for the key to change between rendering so that there isn't mass confusion on next render 
	 */
	private int absorbs;
	
	/**
	 * Is the input button current down 
	 */
	private boolean down;
	
	/**
	 * Is the input button currently clicked 
	 */
	private boolean clicked;
	
	//--------------------------------------------------------------------------
	//
	//  Methods
	//
	//--------------------------------------------------------------------------
	
	//----------------------------------
	// Public
	//----------------------------------
	
	/**
	 * Toggle the input button 
	 * 
	 * @param 	 pressed with the boolean toggle 
	 */
	void toggle( boolean pressed ) {
		
		//If pressed is not equal to down set it 
		if ( pressed != this.down )
			this.down = pressed;
		
		//Up the pressed count 
		if ( pressed )
			this.presses++;
	}

	
	//----------------------------------
	// Private
	//----------------------------------
	
	//----------------------------------
	// Overridden / Implemented
	//----------------------------------
	
	/**
	 * Tick the input key 
	 */
	public void tick()
	{
		//Check that the absorbs is less than the presses 
		if ( this.absorbs < this.presses) 
		{
			//If it is up the absorbs and then toggle clicked to true
			this.absorbs++;
			
			this.setClicked(true);
		}
		else
		{
			//If not toggle clicked to false 
			this.setClicked(false);
		}
	}	
}
